package repository

import (
	"context"
	"demo/domain/model"
	"gorm.io/gorm"
)

type domainConfRepository struct {
	db *gorm.DB
}

func (d domainConfRepository) FindByDomain(ctx context.Context, domain string) (*int64, error) {
	var entity int64
	err := d.db.WithContext(ctx).Raw("select id from domain_conf where deleted = 0 and  domain_value = ?", domain).First(&entity).Error
	return &entity, err
}

func (d domainConfRepository) Save(ctx context.Context, entity *model.DomainConf) error {
	return d.db.WithContext(ctx).Create(entity).Error
}

// NewDomainConfRepository 创建一个新的 Repository 实例
func NewDomainConfRepository(db *gorm.DB) model.DomainConfRepository {
	return &domainConfRepository{db: db}
}
